
#include <config.h>

#ifndef __MEMORY_H
#  define __MEMORY_H

#  ifdef CONF_SYS_AMD64
#    ifdef CONF_MEMMODE_2M_LONG

struct __PML4E { /* Page Map Level 4 Entry */

  unsigned char  flags;
  unsigned       resv : 1;
  unsigned       low_avl : 3;
  unsigned       base_low_4 : 4;
  unsigned short base_lo_mid_16;
  unsigned short base_hi_mid_16;
  unsigned       base_high_4 : 4;
  unsigned char  mid_avl;
  unsigned       high_avl : 7;
  unsigned       nx : 1;

} __attribute__ ((packed));

typedef struct __PML4E PML4E;
typedef struct __PML4E PDPE;  // A Page Directory Pointer entry is identical to
                              // a Page Map Level 4 Entry.

struct __PDE { /* Page Directory Entry */

  unsigned char  flags;
  unsigned       global : 1;
  unsigned       low_avl : 3;
  unsigned       pat : 1;
  unsigned       low_rsvd : 3;
  unsigned       high_resv : 5;
  unsigned       base_low_3 : 3;
  unsigned char  base_mid_8;
  unsigned short base_mid_16;
  unsigned       base_high_2;
  unsigned char  mid_avl;
  unsigned       high_avl : 7;
  unsigned       nx : 1;

} __attribute__ ((packed));

typedef struct __PDE PDE;

#    define 2M_LONG_FLAG_PRES 0x01
#    define 2M_LONG_FLAG_RW   0x02
#    define 2M_LONG_FLAG_US   0x04
#    define 2M_LONG_FLAG_PWT  0x08
#    define 2M_LONG_FLAG_PCD  0x10
#    define 2M_LONG_FLAG_ACSD 0x20
#    define 2M_LONG_FLAG_DRTY 0x40
#    define 2M_LONG_FLAG_GLBL 0x01

#    endif
#  endif

extern unsigned long int physical_memory;

#endif
